import * as Types from '../constant/ActionTypes';

let count = 0;

const loading = (state = false, action = {}) => {
  switch (action.type) {
    case Types.LOADING_SHOW:
      count += 1;
      return true;
    case Types.LOADING_HIDE:
      if (count > 0) count -= 1;
      return count === 0 ? false : state;
    default:
      return state;
  }
};

export default loading;